package com.wangyan.javabean2doc;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.wangyan.javabean2doc.ui.TableUI;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;

/**
 * @author wangyan
 * @date 2024/01/26/17:42
 * @description
 */
public class MyDialogWrapper extends DialogWrapper {
    private final JPanel rootPanel = new JPanel();
    private final TableUI tableUI = new TableUI();

    protected MyDialogWrapper(@Nullable Project project, List<RowData> rowDataList) {
        super(project);
        setOKButtonText("复制表");
        tableUI.fillData(project, rowDataList);
        rootPanel.add(tableUI.getRoot());
        setModal(false);
        super.init();

    }

    @Override
    protected void doOKAction() {
        try {
            tableUI.copy();
        } catch (Exception e) {
            Messages.showMessageDialog(rootPanel, "复制出错！", "警告", Messages.getInformationIcon());

        }
        Messages.showMessageDialog(rootPanel, "复制成功！", "消息", Messages.getInformationIcon());
        this.dispose();
    }


    @Override
    protected @Nullable JComponent createCenterPanel() {
        return rootPanel;
    }
}
